<?php

function helplink ($link, $anquor = '')
{
    $link = helpurl($link, $anquor);
    return "<a href=\"javascript:var win = window.open('".$link."', 'help', 'width=800,height=580,scrollbars,resizable')\"><img align=\"absmiddle\" border=\"0\" src=\"".$GLOBALS['cfgPaths']["imgresUrl"]."/help.gif\"></a>";    
}

function helpurl ($link, $anquor = '')
{
    if ($anquor)
        return $GLOBALS['env']->getServer("SCRIPT_NAME").'/helpwin/frame/anquor/'.$anquor.$link;
    else
        return $GLOBALS['env']->getServer("SCRIPT_NAME").'/helpwin/frame/top'.$link;
}

function syn_unlink ($file) {
	if (!file_exists($file)) return false;
	return @unlink($file);
}

function syn_rmdir ($file) {
	if (!syn_dirempty($file)) return false;
	return @rmdir($file);
}

function syn_dirempty ($dir) {
	$d = dir($dir);
	while ($file = $d->read()) {
		if ($file != '.' && $file != '..') {
			$d->close();
			return false;
		}
	}
	return true;
}

function xicsEdition ($tests) {
    if (!is_array($tests)) $tests = array($tests);
    foreach ($tests as $test) {
        if (xicsEdition_hlp($test))
            return true;
    }
    return false;
}

function xicsEdition_hlp ($test) {
    switch ($test) {
        case 'pro':
            return (isset($GLOBALS['cfgProVersion']) && $GLOBALS['cfgProVersion']);
        case 'light':
            return (empty($GLOBALS['cfgMicroVersion']) && empty($GLOBALS['cfgProVersion']));
            break;
        case 'micro':
            return (isset($GLOBALS['cfgMicroVersion']) && $GLOBALS['cfgMicroVersion']);
    }
}

/** internal **/
function loadModuleCfg ($filepath) {
    $dir = dir(dirname($filepath).'/modules');
    if (!$dir) die ('Could not load module configs from "'.dirname($filepath).'/modules"');
    while (false !== ($entry = $dir->read())) {
        if ($entry[0] != '.' && preg_match('/.inc.php$/', $entry)) {
            include(dirname($filepath).'/modules/'.$entry);
        }
    }
}

/** Util functions **/
function array_last ($array) {
    return $array[count($array)-1];
}

?>